package admin

import (
	"context"
	"errors"

	"server/internal/svc"
	"server/internal/types"
	"server/models"
	"server/utils"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type ShippingTemplateInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShippingTemplateInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShippingTemplateInfoLogic {
	return &ShippingTemplateInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShippingTemplateInfoLogic) ShippingTemplateInfo(req *types.IdForm) (resp *types.ShippingTemplateResp, err error) {
	data := &models.ShippingTemplate{}
	if !utils.GetDataById(req.Id, data) {
		return nil, errors.New("运费模板不存在")
	}
	resp = &types.ShippingTemplateResp{}
	copier.Copy(resp, data)
	return resp, nil
}
